package com.typhoon.service;

import com.typhoon.dao.UserDao;
import com.typhoon.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/17 下午2:24
 * @description
 * @modified by
 * @since V2.0.0
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private UserDao userDao;

    @Transactional
    public void saveAndDel(User user) {
        user = this.userDao.save(user);
        if(null == user || null == user.getId()) {
            throw new RuntimeException("save user failed");
        }
        int rs = this.userDao.deleteByPK(user.getId());
        if(rs <= 0) {
            throw new RuntimeException("delete user failed");
        }
    }

}
